﻿using Codeflows.Tracking;
using Ninject;

namespace Codeflows.Contrib.Ninject
{
    public class NinjectCodeflowTrackerFactory : ICodeflowTrackerFactory
    {
        private readonly IKernel _kernel;

        public NinjectCodeflowTrackerFactory(IKernel kernel)
        {
            _kernel = kernel;
        }

        public DisposableContext<ICodeflowTracker> CreateTracker()
        {
            var tracker = _kernel.Get<ICodeflowTracker>();

            return new DisposableContext<ICodeflowTracker>(tracker, instance => _kernel.Release(instance));
        }
    }
}